package com.example.mapreduce.partiton2;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * Created with IntelliJ IDEA.
 * ClassName: ProvincePartitoner
 * Package: com.example.mapreduce.partiton2
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-16
 * Time: 17:24
 */

//这里的kv 是map输出的kv
public class ProvincePartitioner extends Partitioner<Text, FlowBean> {
    @Override
    public int getPartition(Text text, FlowBean flowBean, int i) {
        //text 是手机号
        //按照是手机号的前三位分区
        String phone = text.toString();
        //取前三位
        String s = phone.substring(0, 3);
        //返回值 是int
        int partition;
        //判断
        if ("136".equals(s)) {
            //0号分区
            partition = 0;
        } else if ("137".equals(s)) {
            partition = 1;
        } else if ("138".equals(s)) {
            partition = 2;
        } else if ("139".equals(s)) {
            partition = 3;
        } else {
            partition = 4;
        }
        return partition;

    }
}
